<?php

class Ajax extends Controller
{

	function Intro()
		{
			parent::Controller();
		}//кінець методу

	function index()
		{
			session_start();
			$this->loadSettings();
			//$this->load->plugin('captcha');
			$datas	= $this->common->basicvars();
			global $userId,$now,$adminName,$adminEmail,$siteName,$siteTitle;

			if($_POST['action']=='register')
				{
					$firstname		= explode(" ",$_POST['firstname']);
					$lastname		= explode(" ",$_POST['lastname']);
					$email			= $_POST['email'];
					$pass			= $_POST['pass'];

					
					$isRecordExist	= getTotRec("user_id","users","email='$email'");

					if($firstname=='' or $lastname=='' or $email=='' or $pass==''/* or $captcha==''*/) {
						$result	= "Помилка: Заповнення усіх полів обов'язкове";
					} elseif(strlen($firstname)<2) {
						$result= "Помилка: Невірне ім’я, довжина імені не може бути менше 2 символів";
					} elseif(strlen($lastname)<2) {
						$result= "Помилка: Невірне призвіще, довжина призвіща не може бути менше 2 символів";
					} elseif(!isValidEmail($email)) {
						$result= "Помилка: Невірний формат поштової скриньки";
					} elseif(strlen($pass)<6) {
						$result= "Помилка:  Пароль занадто короткий, допустимий від 6 символів. Спробуйте інший";
					} elseif($isRecordExist) {
						$result	= "Помилка: Ця поштова скринька вже використовується іншим користувачем. Спробуйте іншу";	
					} else {
							$encPass	= md5($pass);//шифрування паролю
							$randNo		= rand();
							$fieldList	= "firstname='$firstname[0]', lastname='$lastname[0]', password='$encPass', show_password='$pass', email='$email', registered_date='$now', activation_key='$randNo'";
							insertRecord('users', $fieldList);
							$result	= "success";
						}
					echo $result;
				}//кінець процесу реєстрації
			elseif($_POST['action']=="generalProfile")
				{
					$result		= "Данні небули збережені.";

					$userId			= $_POST['userId'];
					$sex			= $_POST['sex'];
					$relation		= $_POST['relation'];
					$lookingFor		= $_POST['lookingFor'];
					$interestedIn	= $_POST['interestedIn'];
					$bd				= $_POST['bd'];
					$bm				= $_POST['bm'];
					$by				= $_POST['by'];
					if($bd !='-1' and $bm!='-1' and $by!='-1')
						$birthday	= $bd."-".$bm."-".$by;
					else
						$birthday	= '';
					$bdVisible	= $_POST['bd_visible'];
					$city		= $_POST['city'];
					$politics	= $_POST['politics'];
					$religion	= $_POST['religion'];
					$fieldList	= " user_id='$userId', sex_id='$sex', interested_in_id ='$interestedIn', relation_id='$relation',
									looking_for_id='$lookingFor', birthday='$birthday', birthday_visibility_id='$bdVisible',
									city='$city', political_id='$politics', religious_view='$religion' ";

					if(IsRecordExist4Add('general_profile','general_profile_id',"user_id='$userId'"))
						{
							if(updateRecords('general_profile', $fieldList,"user_id='$userId'"))
								$result	= "Основну інформацію успішно збережено";
						}
					else
						{
							if(insertRecord('general_profile', $fieldList))
								$result	= "Основну інформацію успішно збережено";
						}
					echo $result;
				}//кінець редагування базової інформації в профілі
			elseif($_POST['action']=="submit_personal")
				{
					$result		= "Данні небули збережені.";

					$userId		= $_POST['userId'];
					$activities	= $_POST['activities'];
					$interests	= $_POST['interests'];
					$music		= $_POST['music'];
					$tv			= $_POST['tv'];
					$movies		= $_POST['movies'];
					$books		= $_POST['books'];
					$quote		= $_POST['quote'];
					$about_me	= $_POST['about_me'];
										
					
					$fieldList	= ' user_id="'.$userId.'", activities="'.$activities.'", interests="'.$interests.'", favorite_music="'.$music.'",
									favorite_tv_shows="'.$tv.'", favorite_movies="'.$movies.'", favorite_books="'.$books.'",
									favorite_quotes="'.$quote.'", about_me="'.$about_me.'" ';

					if(IsRecordExist4Add('member_personal','personal_id',"user_id='$userId'"))
						{
							if(updateRecords('member_personal', $fieldList,"user_id='$userId'"))
								$result	= "Персональну інформацію успішно збережено";
						}
					else
						{
							if(insertRecord('member_personal', $fieldList))
								$result	= "Персональну інформацію успішно збережено";
						}
						
					echo $result;
				}
			elseif($_POST['action']=="submit_contact")
				{
					$result		= "Данні небули збережені.";

					$userId		= $_POST['userId'];
					$mobile		= $_POST['mobile'];
					$land_line	= $_POST['land_line'];
					$address	= $_POST['address'];
					$website	= $_POST['website'];
					$icq		= $_POST['icq'];
					$skype		= $_POST['skype'];

					$fieldList	= ' mobile="'.$mobile.'", land_line="'.$land_line.'", address="'.$address.'",
									website="'.$website.'", icq="'.$icq.'", skype="'.$skype.'" ';
								
					if(IsRecordExist4Add('contact_profile','contact_id',"user_id='$userId'"))
						{
							if(updateRecords('contact_profile', $fieldList,"user_id='$userId'"))
								$result	= "Контактну інформацію успішно збережено";
						}
					else
						{
							if(insertRecord('contact_profile', $fieldList))
								$result	= "Контактну інформацію успішно збережено";
						}
						
					echo $result;
				}
			elseif($_POST['action']=='changeUserStatus')
				{
					$this->load->helper('smiley');
					$uid		= $_POST['uid'];
					$dowhat		= $_POST['dowhat'];
					$userName	= $this->common->getUsername($uid);
					if($dowhat=='store')
						{
							$statusId	= $_POST['status'];
							
							updateRecords("users","screen_status_id='$statusId', screen_status_changed_date='$now'","user_id=".$uid);
							$rs	= getRow("users","screen_status_id,screen_status_changed_date","user_id='$uid'");
							$status		= parse_smileys($rs['screen_status_id'], "http://demo.maax.ws/application/images/smileys/").'<p><a href="javascript: void(0);" onclick="show_div(\'screen_status_change_div\');close_div(\'screen_status_div\');"><b>[ змінити статус ]</b></a></p>';


						}
					else
						{
							updateRecords("users","screen_status_id='', screen_status_changed_date=''","user_id=".$uid);
							$status	= '<p><a href="javascript: void(0);" onclick="show_div(\'screen_status_change_div\');close_div(\'screen_status_div\');"><b>[ змінити статус ]</b></a></p>';
						}
					echo $status;
				}//end changeUserStatus
			elseif($_POST['action']=='remove_school')
				{
					if($_POST['education']=='education_1')
						$schoolType	= 'education1';
					elseif($_POST['education']=='education_2')
						$schoolType	= 'education2';
					elseif($_POST['education']=='education_3')
						$schoolType	= 'education3';
					elseif($_POST['education']=='education_4')
						$schoolType	= 'education4';
					if(mysql_query("DELETE FROM school_education WHERE user_id='$userId' AND school_type='$schoolType'"))
						{
							$totSchools	= getTotRec("school_edu_id","school_education","user_id='$userId'");
							if($totSchools<1)
								mysql_query("DELETE FROM education_profile WHERE user_id='$userId'");
							echo "true";
						}
					else
						echo "false";
				}//end remove school				
			elseif($_POST['action']=='remove_job')
				{
					if($_POST['job']=='work_history_1')
						$jobType	= 'job1';
					elseif($_POST['job']=='work_history_2')
						$jobType	= 'job2';
					elseif($_POST['job']=='work_history_3')
						$jobType	= 'job3';
					elseif($_POST['job']=='work_history_4')
						$jobType	= 'job4';
					if(mysql_query("DELETE FROM work_profile WHERE user_id='$userId' AND job_type='$jobType'"))
						echo "true";
					else
						echo "false";

				}
			elseif($_POST['action']=='add_friend')
				{
					$friendId				= $_POST['friendId'];
					$message				= $_POST['msg'];
					if(trim($message)!='')
						$message	= "The sender\'s private message<br>".$message;

					$alreadyExist	= getTotRec("friends_list_id", "friends_list", "user_id='$userId' AND friend_id='$friendId'");
					
					if($alreadyExist>0)
						echo '<div class="msg-error">Помилка: Ви вже додали цього користувача до списку ваших друзів</div>';
					else
						{
							$friendRs	= getRow("users","firstname, lastname,email","user_id='$friendId'");

							$friendsUrl	= '<a href="'.base_url().'friends">'.base_url().'friends</a>';
							$this->load->library('email');	//loads email library
							$config['mailtype'] = 'html';
							$this->email->initialize($config);

							$usrRs		= getRow("users","firstname, lastname ,email","user_id='$userId'");
							$senderName	= ''.$usrRs['firstname'].' '.$usrRs['lastname'].'';
							$senderEmail= $usrRs['email'];

							$this->email->from($adminEmail, $adminName);
							$this->email->to($friendRs['email']);

							$tempRs			= getRow("mail_templates","template_subject,template_content","template_id=5");//for Adds me as a friend(template_id=5)
							$spArray		= array("~~senderName~~"=>$senderName,"~~privateMessage~~"=>$message,"~~siteName~~"=>$siteName,"~~attachUrl~~"=>$friendsUrl,"~~adminName~~"=>$adminName);
							$mailSubject	= nl2br(replaceSpVariables($spArray,$tempRs['template_subject']));//mail subject
							$mailContent	= nl2br(replaceSpVariables($spArray,$tempRs['template_content']));//mail subject

							$this->email->subject($mailSubject);											//set subject to send mail
							$this->email->message($mailContent);											//set message to send mail
							//send mail
							if($this->email->send())
								{
									//store email friends in database
									if(insertRecord("friends_list","user_id='$userId', friend_mail='".$friendRs['email']."', friend_id='$friendId', datestamp='$now'"))
										echo "success";
									else
										echo '<div class="msg-error">Помилка: Помилка додання данних друга до бази данних</div>';
								}//end email send
							else
								echo '<div class="msg-error">Помилка: Відправити повідомлення на поштову скриньку невдалося</div>';
						}//end validation
				}//end add friend			
			elseif($_POST['action']=='sendMessage')
				{
					$sendType	= $_POST['actionType'];		//get send type, such as to event, or to friend
					$toname		= explode(" ",$_POST['toname']);			//reciever name(eventname,friend name)
					$subject	= $_POST['subject'];		//message subject
					$message	= $_POST['content'];		//message original content
					if($message=='')
						$msg	= "<div class='msg-error'>Помилка: Неможливо відправити пусте повідомлення</div> |no";
					else
							if($sendType=='single_user')//check whether message for group
							{
								$userID		= $_POST['actionId'];		//get event id from ajax.js
								if($this->store2Inbox($userID,$subject,$message))//store this user details to inbox table
									{
										$msg	= "<div class='msg-good'>Повідомлення успішно відправлено</div> sent|yes";
										$this->store2Sent($userID,$subject,$message,'friend');//store user details to sent(message) table
									}
								else
									$msg		= "<div class='msg-error'>Помилка при відправленні повідомлення</div>|no";
							}
						else//check whether message for friend
							{
								$usrRs		= getRow('users',"user_id, email, firstname, lastname","firstname='$toname[0]' AND lastname='$toname[1]'");
								$cur_usrRs	= getRow("users","user_id, email, firstname, lastname","user_id='$userId'");
								$userName	= ''.$cur_usrRs['firstname'].' '.$cur_usrRs['lastname'].'';
								$userEmail	= $cur_usrRs['email'];												//get current user name

								$this->load->library('email');												//load email library
								$config['mailtype'] = 'html';
								$this->email->initialize($config);
								$this->email->to($usrRs['email'],$toname);
								$this->email->from($adminEmail, $siteTitle);
								$mailSubject	= 'У вас нове повідомлення від '.$userName;
								base_url().'messages/inbox';
								$this->email->subject($mailSubject);											//set subject to send mail
								if($usrRs['email'] =='')//if no user for this username
									$msg	= "<div class='msg-error'>Помилка: Невказаний отримувач</div>|no";
								else {

								if($subject=='')
								$subject	= "(немає теми)";		//message subject
								
									if($this->store2Inbox($usrRs[user_id],$subject,$message))//store this user details to inbox table
										{
											$notifiyRs	= getRow("users_status","notification_status","notification_id=1 AND user_id=".$usrRs[user_id]);
											if($notifiyRs[notification_status]=='1' or $notifiyRs[notification_status]=='')
												{
													$getMsgId	= getRow('inbox_messages',"inbox_message_id","from_id='".$userId."' and  user_id=".$usrRs[user_id]." and  subject='".$subject."' and  message='".$message."'");
													$mailMessage	= ''.$cur_usrRs['firstname'].' '.$cur_usrRs['lastname'].' надіслав Вам повідомлення.<br><br>Для того щоб прочитати це повідомлення, перейдіть за посиланням що нижче<br><br>'.base_url().'messages/read/i_'.$getMsgId[inbox_message_id];
													$this->email->message($mailMessage);											//set message to send mail
													//send mail
													$this->email->send();
													$msg	= "<div class='msg-good'>Повідомлення успішно відправлено</div>|yes";
													$this->store2Sent($usrRs[user_id],$subject,$message,'friend');//store user details to sent(message) table
												}
											else
												{
													$this->store2Sent($usrRs[user_id],$subject,$message,'friend');//store user details to sent(message) table
													$msg		= "<div class='msg-good'>Повідомлення успішно відправлено</div>|yes";
												}//if
										}//if
									}
							}//else
					echo $msg;
				}//end sendMessage()
				
			elseif($_POST['action']=="message_mark_unread" or $_POST['action']=="message_mark_read" or $_POST['action']=="message_move_to_trash" or $_POST['action']=="message_select_action")
				{
					$doit	= $_POST['action'];
					$msgIds	= $_POST['msgIds'];
					$folder	= $_POST['folder'];
					//$result='nothing';
					if($msgIds =='')
						$result ="<p align='center'>Жодного повідмолення не обрано</p>";
					else
						{
							$msgIds	= explode(",",$msgIds);
							$totMsg	= count($msgIds)-1;
							$condition 		= '';
							$inboxCondition = '';
							$sentCondition 	= '';

							if($folder=='inbox')
								{
									$fieldName	= " inbox_message_id ";
									$table		= "inbox_messages";
								}
							else
								{
									$fieldName	= " message_id ";
									$table		= "messages";
								}
							for($i=0;$i<$totMsg;$i++)
								{
									if($i == $totMsg-1)
										$sentCondition .= $fieldName."=".$msgIds[$i];
									else
										$sentCondition .= $fieldName."=".$msgIds[$i]." OR ";
								}

							if($doit =='message_mark_read' and $sentCondition !='')
								$query	= "UPDATE ".$table." SET message_status='read' WHERE ".$sentCondition." AND user_id='$userId'";
							elseif($doit =='message_mark_unread' and $sentCondition !='')
								$query	= "UPDATE ".$table." SET message_status='unread' WHERE ".$sentCondition." AND user_id='$userId'";
							elseif($doit =='message_move_to_trash' and $sentCondition !='')
								$query	= "DELETE FROM ".$table." WHERE ".$sentCondition." AND user_id='$userId'";
							else
								$query	= '';
							//if($query!='')
							mysql_query($query);
							if($folder=='inbox')
								{
									$selQuery	= 	"SELECT subject,message,from_id,datestamp,inbox_message_id,message_status
													FROM inbox_messages
													WHERE user_id='$userId' ORDER BY datestamp DESC";
									$result		= $this->common->listMessage($selQuery,'inbox');
								}
							else
								{
									$selQuery	= 	"SELECT subject,to_id ,datestamp,message_id,message, message_status,to_name, to_type
													FROM messages
													WHERE user_id='$userId' ORDER BY datestamp DESC";
									$result		= $this->common->listMessage($selQuery,'sent');
								}
						}
						
					echo $result;

				}//end markread, mark unread
			elseif($_POST['action']=="msgSingleDel")
				{
					$splitId	= explode("_",$_POST['delId']);
					//print_r($splitId);
					if($splitId[0]=='inbox')
						{
							$query		= "DELETE FROM inbox_messages WHERE inbox_message_id=".$splitId[1];
							mysql_query($query);
							$selQuery	= 	"SELECT subject,message,from_id,datestamp,inbox_message_id,message_status
											FROM inbox_messages
											WHERE user_id='$userId' ORDER BY datestamp DESC";
							$result		= $this->common->listMessage($selQuery,'inbox');
						}
					elseif($splitId[0]=='sent')
						{
							$query		= 	"DELETE FROM messages WHERE message_id=".$splitId[1];
							mysql_query($query);
							$selQuery	= 	"SELECT subject,to_id ,datestamp,message_id,message, message_status,to_name,to_type
											FROM messages
											WHERE user_id='$userId' ORDER BY datestamp DESC";
							$result		= $this->common->listMessage($selQuery,'sent');
						}
					echo $result;
				}
			elseif($_POST['action']=="wallMsgDel")
				{
					$delId		= $_POST['delId'];
					$profileId	= $_POST['profileId'];
					$userId		= $_POST['userId'];

					$query		= 	"DELETE FROM profile_wall WHERE profile_wall_id='$delId' AND posted_to='$profileId' AND posted_by='$userId'";
					mysql_query($query);
					
					$result = $this->showWall($profileId, $userId);
					
					echo $result;
				}
			elseif($_POST['action']=='postToProfile')
				{
					$postedBy	= $_POST['by'];
					$postedTo	= $_POST['to'];
					$postedValue= $_POST['content'];
					$dateStamp 	= time();
					
					$query		= 	"INSERT INTO profile_wall SET posted_by='$postedBy', posted_to='$postedTo',wall_post='$postedValue',datestamp='$dateStamp'";
					mysql_query($query);

					$result = $this->showWall($postedTo, $postedBy);
		
					echo $result;	
				}//end postToProfile
			elseif($_POST['action']=='postToWall')
				{
					$postedBy	= $_POST['by'];
					$postedTo	= $_POST['to'];
					$postedValue= $_POST['content'];
					$dateStamp 	= time();
					
					$query		= 	"INSERT INTO profile_wall SET posted_by='$postedBy', posted_to='$postedTo',wall_post='$postedValue',datestamp='$dateStamp'";
					mysql_query($query);

					$currentPage	= base_url();
					$result = ''.$currentPage.'user/profile/'.$postedTo.'';
		
					echo $result;	
				}//end postToProfile
				
		}
	
	function showWall($profileId,$userId)
		{
			$this->load->helper('typography');
			$this->load->helper('smiley');
			$siteVars		= $this->common->getSiteVars();
			$currentPage	= base_url();
			
			$query	= "SELECT profile_wall_id, wall_post,posted_by,datestamp FROM profile_wall WHERE posted_to='$profileId' ORDER BY datestamp DESC ";
			$res	= mysql_query($query);
			
					if($res)
						{
							while($rs=mysql_fetch_object($res))
								{
									$avatar		= $this->common->getAvatar($rs->posted_by);
									
									$delId 		= $rs->profile_wall_id;
									$postDate	= date('d.m.Y',$rs->datestamp);
									$postTime	= date('h:i',$rs->datestamp);
									
									$postedBy		= $this->common->getUsername($rs->posted_by);
									$profileUrl		= base_url().'user/profile/'.$rs->posted_by;
									$face2faceUrl	= base_url().'profile/face2face/'.$profileId.'/'.$rs->posted_by;
									
									$privatemsgUrl = '<font style="color: #ccc;">|</font> <a href="'.base_url().'messages/compose/'.$rs->posted_by.'">приватне повідомлення</a>';							
									$post2wallUrl = '<font style="color: #ccc;">|</font> <a href="'.base_url().'profile/post2wall/'.$rs->posted_by.'">написати на стіні</a>';							
									$delwallpost = '<font style="color: #ccc;">|</font> <a href="javascript:void(0);" style="text-decoration:none;" onclick="javascript:wallMsgDelete(\''.$delId.'\', \''.$profileId.'\', \''.$rs->posted_by.'\', \''.$currentPage.'\');">видалити</a>';
									
									$delpost = '';
									$prmsg = '';
									
									if ($profileId == $userId || $userId == $rs->posted_by ) {
										$delpost .= $delwallpost;
									}
									elseif ($profileId != $userId || $userId != $rs->posted_by ) {
										$prmsg .= $privatemsgUrl;
									}
									
									$content	.= '<li id="comment">
													<div class="comment-author">
													<a href="'.$profileUrl.'"><b>'.$postedBy.'</b></a> <span class="commdate" >'.$postDate.' @ '.$postTime.'</span> '.$this->common->offline($rs->posted_by, 'wall').'</div>
													<div class="comment-text ">'.parse_smileys(nl2br_except_pre($rs->wall_post), "http://demo.maax.ws/application/images/smileys/").'&nbsp;
													<p id="walloptions"><small><a href="'.$face2faceUrl.'">віч-на-віч</a> '.$post2wallUrl.' '.$prmsg.' '.$delpost.' </small></p>
													</div>
													</li>';
								}//end while
						}
						
						$userAvatar	= $this->common->getAvatar($profileId);						
						$postInterface	= $this->postWall2Profile($userId,$profileId, '');
						
						$content	= '
							<div id="wall_post_result">
							<div id="profile_postcomment">
							'.$postInterface.'<table width="100%"><ol class="commentlist">'.$content.'</ol></table></div>';

			return $content;
		}//showWall()

	function friendslist($listId,$listFor)
		{
			global $userId;
			//echo "SELECT friend_id FROM friends_list WHERE user_id='$userId' AND friend_id<>'$userId'";
			$currentPage	= base_url();
			$res	= mysql_query("SELECT friend_id AS friend_id FROM `friends_list` WHERE user_id='$userId' and approved_status='yes'
									UNION
									SELECT user_id as friend_id FROM `friends_list` WHERE friend_id='$userId' and approved_status='yes'");
			if($res)
			if($listFor=='group')
				{
					while($rs=mysql_fetch_object($res))
						{
							$recCount	= getTotRec('group_invitation_id',"groups_invitation","receiver_id='$rs->friend_id' AND group_id='$listId'");
							if($recCount<1)
								{
									$usrRs		= getRow('users',"firstname, lastname","user_id='$rs->friend_id'");
									$friends 	.= '<div id="check_friend_'.$rs->friend_id.'">
													<input name="check_'.$rs->friend_id.'" id="check_'.$rs->friend_id.'" type="checkbox" onclick="checkInviteFriends(\''.$rs->friend_id.'\',\''.$listId.'\',\''.$currentPage.'\',\'group\')">
													<label>'.$usrRs['firstname'].' '.$usrRs['lastname'].'</label>
													</div>';
								}
						}
				}
			elseif($listFor=='event')
				{
					while($rs=mysql_fetch_object($res))
						{
							$recCount	= getTotRec('event_invitation_id',"events_invitation","receiver_id='$rs->friend_id' AND event_id='$listId'");
							if($recCount<1)
								{
									$usrRs		= getRow('users',"firstname, lastname","user_id='$rs->friend_id'");
									$friends 	.= '<div id="check_friend_'.$rs->friend_id.'">
													<input name="check_'.$rs->friend_id.'" id="check_'.$rs->friend_id.'" type="checkbox" onclick="checkInviteFriends(\''.$rs->friend_id.'\',\''.$listId.'\',\''.$currentPage.'\',\'event\')">
													<label>'.$usrRs['firstname'].' '.$usrRs['lastname'].'</label>
													</div>';
								}
						}
				}
			return $friends;
		}//end method friendslist

	//store user details to inbox_message table
	function store2Inbox($toid,$subject,$message)
		{
			global $userId,$now;
			//store mail info into inbox_messages table
			$inboxFieldList	= "from_id='$userId',user_id='$toid', subject='$subject', message='$message',datestamp='$now'";
			if(insertRecord('inbox_messages',$inboxFieldList))
				return true;
			else
				return false;
		}
	//store user details to messages table
	function store2Sent($toid,$subject,$message,$type,$typeValue='')
		{
			global $userId,$now;
			//store info at messages table as sent item
			$fieldList	= "user_id='$userId', to_id='$toid', subject='$subject', message='$message',datestamp='$now',to_name='$typeValue',to_type='$type'";
			if(insertRecord('messages',$fieldList))
				return true;
			else
				 return false;
		}

	function postWall2Profile($postedBy,$postedTo,$result)
		{
			$this->load->helper('smiley');
			$this->load->library('table');
		
			$currentPage	= base_url();
			$ajaxLoader		= base_url().'/application/images/ajax-loader.gif';
			
			$image_array = get_clickable_smileys('http://demo.maax.ws/application/images/smileys/');
			$col_array = $this->table->make_columns($image_array, 17);		
			$smiley_table = $this->table->generate($col_array);
			$insert_smiley = js_insert_smiley("wall_form", "post_content");
			
			$content	= '
							<div id="wall_post_ajax_loader" style="display:none; padding: 5px;" align="center"><img src="'.$ajaxLoader.'"></div>
							<div id="wall_post_result"></div>
							<form name="wall_form" method="post">
							<div class="profile_postcomment">
							<textarea style="overflow: hidden; height: 70px; color: rgb(136, 136, 136);" name="post_content" id="post_content" cols="25" class="comment_area" onkeypress="ctrlEnterWall(event);"></textarea>
							'.$insert_smiley.$smiley_table.'
							<div style="text-align: right; margin-top: 5px;">
							<input type="button" name="post_wall" id="post_wall" class="button" value="Надіслати" onclick="post2Profile(\''.$postedBy.'\',\''.$postedTo.'\',\''.$currentPage.'\');">
							</div>
							</form>
							</div></div>';
			return $content;
		}//postWall2Profile()

	function postWall2Wall($postedBy,$postedTo,$result)
		{
			$this->load->helper('smiley');
			$this->load->library('table');
		
			$currentPage	= base_url();
			$ajaxLoader		= base_url().'/application/images/ajax-loader.gif';
			
			$image_array = get_clickable_smileys('http://demo.maax.ws/application/images/smileys/');
			$col_array = $this->table->make_columns($image_array, 17);		
			$smiley_table = $this->table->generate($col_array);
			$insert_smiley = js_insert_smiley("wall_form", "post_content");
			
			$content	= '
							<div id="wall_post_ajax_loader" style="display:none; padding: 5px;" align="center"><img src="'.$ajaxLoader.'"></div>
							<div id="wall_post_result"></div>
							<form name="wall_form" method="post">
							<div class="profile_postcomment">
							<textarea style="overflow: hidden; height: 70px; color: rgb(136, 136, 136);" name="post_content" id="post_content" cols="25" class="comment_area" onkeypress="ctrlEnterWall(event);"></textarea>
							'.$insert_smiley.$smiley_table.'
							<div style="text-align: right; margin-top: 5px;">
							<input type="button" name="post_wall" id="post_wall" class="button" value="Надіслати" onclick="post2Wall(\''.$postedBy.'\',\''.$postedTo.'\',\''.$currentPage.'\');">
							</div>
							</form>
							</div></div>';
			return $content;
		}//postWall2Profile()
		
	function loadSettings()
		{
			global $userId,$now,$adminName,$adminEmail,$siteName,$siteTitle;
			$this->load->model('common');

			$userId		= $this->session->userdata('user_id');
			$now		= $this->config->item('now');

			$siteVars	= $this->common->getSiteVars();
			$adminName	= $siteVars['adminName'];
			$adminEmail	= $siteVars['adminEmail'];
			$siteName	= $siteVars['siteName'];
			$siteTitle	= $siteVars['siteTitle'];

		}
}
?>
